//
//  Primer_Range_DemoVC.swift
//  APSwift
//
//  Created by jianbo.pei on 2022/4/29.
//

import UIKit

class Primer_Range_DemoVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        test2()
        test3()
        test4()
    }
    
//    private func test1() {
//        let range1: ClosedRange<Int> = 0...5
//        let range2: Range<Int> = 0..<3
//        let range3: PartialRangeThrough<Int> = ...5
//    }
    
    private func test2() {
        APPrint()
        print("\(#function)")
        /// Note: 字符、字符串也能使用区间运算符，但默认不能用在`for-in`中
        let strRange1 = "cc"..."ff"
        print("\(strRange1.contains("cb"))")  /// false
        print("\(strRange1.contains("dz"))")  /// true
        print("\(strRange1.contains("fg"))")  /// false
        
        let strRange2 = "a"..."f"
        APPrint()
        print("\(strRange2.contains("b"))")  /// true
        print("\(strRange2.contains("g"))")  /// false
        print("\(strRange2.contains("e"))")  /// true
    }
    
    private func test3() {
        APPrint()
        print("\(#function)")
        /// Note: `\0`到`~`囊括了所有的可能要用到的ASCII字符
        let characterRange: ClosedRange<Character> = "\0"..."~"
        print("\(characterRange.contains("G"))")  /// true
    }
    
    private func test4() {
        #warning("待深入")
        APPrint()
        print("\(#function)")
        /// 带间隔的区间值
        let maxNum = 11
        let numInterval = 2
        for num in stride(from: 4, through: maxNum, by: numInterval) {
            print("\(num)")
        }
        
        APPrint()
        for num in stride(from: 4, to: maxNum, by: numInterval) {
            print("\(num)")
        }
    }

}
